# utils/unified_formats.py

from pydantic import BaseModel, Field, field_validator
from typing import List, Dict, Any

class Skills(BaseModel):
    """一个专门用于技能的子模型，确保结构一致"""
    hard_skills: List[str] = Field(default_factory=list)
    soft_skills: List[str] = Field(default_factory=list) # 将软技能也移入此结构

class UnifiedResume(BaseModel):
    #'skills' 字段现在必须是一个 Skills 对象
    skills: Skills = Field(default_factory=Skills)
    languages: List[str] = Field(default_factory=list)
    education_level: str = ""
    experience_years: int = 0
    other_tags: List[str] = Field(default_factory=list)

    # 验证器保持不变
    @field_validator('experience_years', mode='before')
    @classmethod
    def clean_experience_years(cls, v: Any) -> int:
        if v is None: return 0
        try: return int(v)
        except (ValueError, TypeError): return 0

    @field_validator('education_level', mode='before')
    @classmethod
    def validate_education_level(cls, v: Any) -> str:
        valid_levels = ["博士", "硕士", "本科", "大专", "不限"]
        if v in valid_levels: return v
        if v == "学士": return "本科"
        return ""

class DimensionWeights(BaseModel):
    #增加 soft_skills 的权重，因为现在它是一个独立的匹配维度
    hard_skills: int = 40
    soft_skills: int = 15
    experience_years: int = 30
    education_level: int = 10
    languages: int = 5
    other_tags: int = 0

class UnifiedJD(UnifiedResume):
    dimension_weights: DimensionWeights = Field(default_factory=DimensionWeights) 